Keyword and Optional Arguments in PLT Scheme

نویسندگان

  • Matthew Flatt
  • Eli Barzilay
چکیده

The lambda and procedure-application forms in PLT Scheme support arguments that are tagged with keywords, instead of identified by position, as well as optional arguments with default values. Unlike previous keyword-argument systems for Scheme, a keyword is not self-quoting as an expression, and keyword arguments use a different calling convention than non-keyword arguments. Consequently, a keyword serves more reliably (e.g., in terms of error reporting) as a lightweight syntactic delimiter on procedure arguments. Our design requires no changes to the PLT Scheme core compiler, because lambda and application forms that support keywords are implemented by macros over conventional core forms that lack keyword support. 1. Using Keyword and Optional Arguments A rich programming language offers many ways to abstract and parameterize code. In Scheme, first-class procedures are the primary means of abstraction, and procedures are unquestionably the right vehicle for parameterizing code with respect to a few run-time values. For parameterization over larger sets of values, however, Scheme procedures quickly become inconvenient. Keyword and optional arguments support tasks that need more arguments than fit comfortably into procedures, but where radiacally different forms—such as unit or class in PLT Scheme— are too heavyweight conceptually and notationally. At the same time, keyword and optional arguments offer a smooth extension path for existing procedure-based APIs. Keyword arguments can be added to a procedure to extend its functionality without binding a new identifier (which always carries the danger of colliding with other bindings) and in a way that composes with other such extensions. Keyword arguments in PLT Scheme are supported through a straightforward extension of the lambda, define, and application forms. Lexically, a keyword starts with #: and continues in the same way as an identifier; for example, #:color is a keyword. A keyword is associated with a formal or actual argument by placing the keyword before the argument name or expression. For example, a rectangle procedure that accepts two by-position arguments and one argument with the #:color keyword can be written as 1 See Section 7.7 for a discussion on this choice of keyword syntax. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. 2009 Workshop on Scheme and Functional Programming (define rectangle (lambda (width height #:color color) ....))

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Variable-Arity Polymorphism

Just as some functions have uniform behavior over distinct types, other functions have uniform behavior over distinct arities. These variable-arity functions are widely used in many languages, such as Scheme, Python, and other scripting languages. Statically typed languages, such as C and Java, accommodate modest forms of variable-arity “rest” arguments via homogeneous data structures (plus cas...

متن کامل

A New Approach to Procedures with Variable Arity

This article presents a convenient and efficient procedural interface that allows the definition and use of procedures with optional arguments and indefinite numbers of arguments without resorting to the use of a language-dependent data structure in which to store the arguments. This interface solves many of the problems inherent in the use of lists in Lisp and Scheme to store indefinite number...

متن کامل

Dot-Scheme A PLT Scheme FFI for the .NET framework

This paper presents the design and implementation of dot-scheme, a PLT Scheme Foreign Function Interface to the Microsoft .NET Platform.

متن کامل

OFDM synchronization scheme for Power Line Telecommunications (PLT)

This paper presents a new scheme for OFDM time and frequency synchronization with application in Power Line Telecommunications (PLT). Simulation results show an excellent behavior, even for the low values of SNR in the synchronizer input inherent to PLT. The synchronizer has been prototyped on an FPGA prior to be integrated in the single-chip PLT system.

متن کامل

Component support in PLT Scheme

PLT Scheme (DrScheme and MzScheme) supports COM components with two pieces of software. The rst piece is MzCOM, a COM class that makes a Scheme evaluator available to COM clients. With MzCOM, programmers can embed Scheme code in programs written in mainstream languages such as C++ or Visual BASIC. Some applications can also load MzCOM. The other piece of component-support software is MysterX, w...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2009